local m = require('utils.vim')
local api = vim.api

-- Go to last loc when opening a buffer, see ':h last-position-jump'
m.autocmd('BufReadPost', {
	group = m.augroup('last_loc'),
	callback = function()
		local exclude = { 'gitcommit', 'commit', 'gitrebase' }
		local buf = api.nvim_get_current_buf()
		if vim.tbl_contains(exclude, vim.bo[buf].filetype) then
			return
		end
		local mark = api.nvim_buf_get_mark(buf, '"')
		local lcount = api.nvim_buf_line_count(buf)
		if mark[1] > 0 and mark[1] <= lcount then
			pcall(api.nvim_win_set_cursor, 0, mark)
			return
		end
	end,
})

--EOP
